home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-10-15 | 4.3 KB | 192 lines | [TEXT/PJMM] |
- PROGRAM Sample;
- {}
- { Sample program for using the CIconButton CDEF 1.0}
- { by Ramon M. Felciano}
- { felciano@camis.stanford.edu}
- {}
- { ©1993 Ramon M. Felciano, All Rights Reserved}
- {}
-
- USES
- CIconButtonIntf;
-
- CONST
- kCIconButtonCDEFID = 20;
-
- kSampleMain = 650;
- kSampleAlt = 700;
- kSampleShell = 3210;
-
- atLeft = $08;
- atRight = $0C;
- atTop = $02;
- atBottom = $03;
- VAR
- bPushButton: controlHandle;
-
-
- FUNCTION GetRangedRdm (min, max: integer): integer;
- VAR
- qdRdm: longint;
- range, t: longint;
- BEGIN
- qdRdm := BAND($FFFF, random);
- range := max - min;
- t := (qdRdm * range) DIV 65536; {now 0 <= t <= range}
- GetRangedRdm := t + min;
- END;
-
-
- PROCEDURE doContentClick (window: windowPtr; event: eventRecord);
- VAR
- mouse: point;
- control: controlHandle;
- checkbox, part: integer;
- BEGIN
- setPort(window);
- mouse := event.where;
- globalToLocal(mouse);
- part := findControl(mouse, window, control);
- IF ((part > 0) & (control <> NIL)) THEN
- IF trackControl(control, mouse, NIL) <> 0 THEN
- BEGIN
- checkBox := GetCtlValue(control);
- checkBox := 1 - checkbox;
- SetCtlValue(control, checkbox);
- CASE (GetRangedRdm(1, 5)) OF
- 1:
- CIB_SetTitleOrientation(control, atLeft);
- 2:
- CIB_SetTitleOrientation(control, atRight);
- 3:
- CIB_SetTitleOrientation(control, atTop);
- 4:
- CIB_SetTitleOrientation(control, atBottom);
- OTHERWISE
- BEGIN
- END;
- END;
- invalRect(control^^.contrlRect);
- END;
- END;
-
- PROCEDURE DrawMyWindow (whichWindow: windowPtr; btn: controlHandle);
- VAR
- textRect: rect;
- theCopyright: str255;
- BEGIN
- FillRect(whichWindow^.portRect, gray);
-
- textRect := whichWindow^.portRect;
- InsetRect(textRect, 5, 5);
- textRect.bottom := textRect.top + 44;
- FillRect(textRect, white);
- FrameRect(textRect);
-
- theCopyright := CIB_GetCopyright(btn);
- MoveTo(12, 18);
- DrawString(theCopyright);
-
- MoveTo(12, 30);
- DrawString('Click on the button to randomly change the title orientation.');
-
- MoveTo(12, 42);
- DrawString('Click the close box or hit any key to quit.');
-
- UpdateControls(whichWindow, whichWindow^.visRgn);
- END;
-
-
- PROCEDURE doSimpleWindow;
- LABEL
- 99;
- VAR
- done: boolean;
- theWindow: windowPtr;
- windowPart: integer;
- wRecord: CWindowRecord;
- limitRect: rect;
- rWindow: rect;
-
- itemBox: rect;
-
- theEvent: eventRecord;
- newWindowLoc: point;
- savePort: grafPtr;
- whichWindow: windowPtr;
- tempClip: rgnHandle;
- oe: osErr;
- BEGIN
- bPushButton := NIL;
- done := false;
- theWindow := NIL;
- setRect(rWindow, 50, 50, 450, 200);
- setRect(itemBox, 50, 50, 180, 120);
- limitRect := screenBits.bounds;
- theWindow := NewCWindow(@wRecord, rWindow, 'CIconButton demo', true, documentProc, windowPtr(-1), true, 0);
- IF theWindow = NIL THEN
- GOTO 99;
- SetPort(theWindow);
- PenNormal;
- TextFont(geneva);
- TextSize(9);
- backPat(gray);
-
- ShowWindow(theWindow);
- bPushbutton := newControl(theWindow, itemBox, 'Testing', false, kSampleAlt, kSampleMain, kSampleShell, (16 * kCIconButtonCDEFID), longint(NIL));
- ShowControl(bPushbutton);
- DrawMyWindow(theWindow, bPushButton);
-
-
- REPEAT
- IF WaitNextEvent(everyEvent, theEvent, 0, NIL) THEN
- CASE theEvent.what OF
- keyDown:
- done := true;
- mouseDown:
- BEGIN
- windowPart := FindWindow(theEvent.where, theWindow);
- CASE windowPart OF
- inDrag:
- BEGIN
- DragWindow(theWindow, theEvent.where, limitRect);
- newWindowLoc := theWindow^.portRect.topLeft;
- localToGlobal(newWindowLoc);
- IF newWindowLoc.h MOD 8 <> 0 THEN
- MoveWindow(theWindow, (newWindowLoc.h DIV 8) * 8, newWindowLoc.v, true);
- END;
- inGoAway:
- done := TrackGoAway(theWindow, theEvent.where);
- inContent:
- doContentClick(theWindow, theEvent);
- OTHERWISE
- BEGIN
- END;
- END;
- END;
- updateEvt:
- BEGIN
- GetPort(savePort);
- whichWindow := windowPtr(theEvent.message);
- BeginUpdate(whichWindow);
- DrawMyWindow(theWindow, bPushButton);
- UpdateControls(whichWindow, whichWindow^.visRgn);
- EndUpdate(whichWindow);
- SetPort(savePort);
- END;
- OTHERWISE
- ;
- END;
- UNTIL Done;
- 99:
- IF theWindow <> NIL THEN
- closeWindow(theWindow);
- END;
-
-
-
- BEGIN
- InitCursor;
-
- doSimpleWindow;
- END.